package thinkingJava.chapter14;

import java.util.ArrayList;
import java.util.List;

class CountedInteger {
	private static long counter = 1;
	private final  long id = counter++;
	public String toString() {
		return Long.toString(id);
	}
}
public class FilledClass<T> {
	private Class<T> type;
	public FilledClass (Class<T> type) {
		this.type = type;
	}
	public List<T> create(int nElements) {
		List<T> result = new ArrayList<T>();
		try {
			for (int i = 0; i < nElements ; i++) {
				result.add(type.newInstance());
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return result;
	}
	public static void main(String[] args) {
		FilledClass<CountedInteger> fc = new FilledClass<CountedInteger>(CountedInteger.class);
		System.out.println(fc.create(15));
	}
}
